package com.hz.zbl.mapper;

import com.hz.zbl.model.entity.CourseEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseMapper {

    @Insert("INSERT INTO courses VALUES (null, #{course_name}, #{course_code}, #{teacher_realname}, #{teacher_user_id}, #{section_count}, #{course_time}, #{max_student_count}, #{course_profile}, #{textbook}, #{credits_count}, #{all_score}, #{pass_score}, #{current_section_count}, #{course_year}, #{course_semester}, #{course_room})")
    int addCourse(CourseEntity courseEntity);

    @Delete("DELETE FROM courses WHERE course_name = #{course_name}")
    int deleteCourse(@Param("username") String course_name);

    @Select("SELECT * FROM courses")
    List<CourseEntity> allCourses();

    @Select("SELECT * FROM courses WHERE course_code = #{course_code}")
    CourseEntity selectCourseById(@Param("course_code") String course_code);


    @Update("UPDATE courses SET current_section_count = #{current_section_count} WHERE course_code = #{course_code}")
    int updateCourseCurrentSectionCount(@Param("current_section_count") int current_section_count, @Param("course_code") String course_code);


    @Select("SELECT * FROM courses WHERE teacher_user_id = #{teacher_user_id}")
    List<CourseEntity> selectCoursesByTeacherId(@Param("teacher_user_id") int teacher_user_id);

    @Select(("SELECT * FROM courses WHERE course_name = #{course_name}"))
    CourseEntity selectCourseByCname(@Param("course_name") String course_name);


}
